/**
 * 批量安装软件
 */

const { cmd, sleep, checkTypeSync } = require("../utils");
const os = require("os");
const fs = require("fs");
const path = require("path");

// 初始化
async function init() {
  const directoryPath = path.join(__dirname, "工作软件");
  const files = fs.readdirSync(directoryPath);

  for (let i = 0; i < files.length; i++) {
    const item = files[i];
    const directoryPathInner = path.join(__dirname, `工作软件/${item}`);
    if (checkTypeSync(directoryPathInner) === "2") {
      const filesInner = fs.readdirSync(directoryPathInner);
      if (filesInner.length === 1 && filesInner[0].indexOf(".dmg") > -1) {
        const softWarePath = `${directoryPathInner}/${filesInner[0]}`;
        console.log(softWarePath);

        await installItemSoftWare(softWarePath);
      }
    }
  }
}

async function installItemSoftWare(path) {
  // await sleep(300);
  await cmd(`open ${path}`);
}

init();
